1916B - Two Divisors - CodeForces Solution


constructive algorithms number theory

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
int gcd(int a, int b){
    return b == 0 ? a : gcd(b, a % b);
}
int lcm(int a,int b){
    return ((a*b)/gcd(a,b));
}
bool fun(pair<int,int> a,pair<int,int> b){
    if(a.first!=b.first)
        return a.first<b.first;
    return a.second>b.second;
}
vector<bool> is_prime(1000001, true);
void SieveOfEratosthenes(int n)
{
    is_prime[0] = false;
    is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (is_prime[i] && (long long)i * i <= n) {
            for (int j = i * i; j <= n; j += i)
                is_prime[j] = false;
        }
    }
}
int compute_hash(string const& s) {
    int p = 31, m = 1e14 + 7, hash_value = 0, p_pow = 1;			//good choice for m is large prime number
    for (char c : s) {
        hash_value = (hash_value + (c - 'a' + 1) * p_pow) % m;
        p_pow = (p_pow * p) % m;
    }
    return hash_value;
}
void solve(){
    int a,b;
    cin>>a>>b;
    if(lcm(a,b)==max(a,b))
        cout<<max(a,b)/min(a,b)*lcm(a,b)<<endl;
    else
        cout<<lcm(a,b)<<endl;
}
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--)
        solve();
    return 0;
}


Comments

Submit
0 Comments
More Questions

1547C - Pair Programming
550A - Two Substrings
797B - Odd sum
1093A - Dice Rolling
1360B - Honest Coach
1399C - Boats Competition
1609C - Complex Market Analysis
1657E - Star MST
1143B - Nirvana
1285A - Mezo Playing Zoma
919B - Perfect Number
894A - QAQ
1551A - Polycarp and Coins
313A - Ilya and Bank Account
1469A - Regular Bracket Sequence
919C - Seat Arrangements
1634A - Reverse and Concatenate
1619C - Wrong Addition
1437A - Marketing Scheme
1473B - String LCM
1374A - Required Remainder
1265E - Beautiful Mirrors
1296A - Array with Odd Sum
1385A - Three Pairwise Maximums
911A - Nearest Minimums
102B - Sum of Digits
707A - Brain's Photos
1331B - Limericks
305B - Continued Fractions
1165B - Polycarp Training